package notification.interactionbd;
import java.io.IOException;
import java.io.Reader;
import java.util.Date;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class Postgre {
	
	private static SqlSessionFactory sqlSessionFactory;
	
	public Postgre(String path) throws IOException{
		Reader reader = org.apache.ibatis.io.Resources.getResourceAsReader(path);
		sqlSessionFactory =  new SqlSessionFactoryBuilder().build(reader);
	}
	
	public void InsertToDB(Event event){
		SqlSession session = sqlSessionFactory.openSession();
	    session.insert("SQL.insertEvent",event);
	    session.commit();
	    session.close();
	}
	
	public Event SelectFromDB(int id){
	    SqlSession session = sqlSessionFactory.openSession();
	    Event event = (Event) session.selectOne("SQL.selectEvent",id);
	    session.close();
	    return event;
	}
	
	/*public static void main(String[] args) throws ClassNotFoundException, IOException{
		Date b=java.util.Calendar.getInstance ().getTime();
		String S=1900+b.getYear()+"-"+(b.getMonth()+1)+"-"+b.getDate()+" "+b.getHours()+":"+
		b.getMinutes()+":"+b.getSeconds();
		System.out.println(S);
	}*/
	
} 
/*
  <resultMap id="EventResult" type ="Event">
   
   <result property="devid" column="devid" jdbcType="INTEGER" select="SelectDevid" />
   
   <result property="eventtime" column="eventtime" jdbcType="TIMESTAMP"/>
   
   <result property="pckid" column="pckid" jdbcType="INTEGER"/>
   
   <result property="code" column="code" jdbcType="SMALLINT"/>
   
   <result property="subcode" column="subcode" jdbcType="SMALLINT"/>
   
   <result property="msg" column="msg" jdbcType="VARCHAR"/>
   
 </resultMap>
*/